﻿using OrBitDataModule.Adaptor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Sockets;

namespace OrBitDataModule.CustomEventHandler
{
    public class ReceivedDataEventArgs
    {
        /// <summary>
        /// IP地址
        /// </summary>
        public string IP { get; }
        /// <summary>
        /// 端口号
        /// </summary>
        public int Port { get; }
        /// <summary>
        /// 设备编号
        /// </summary>
        public string MachineNo { get; }
        /// <summary>
        /// 接收数据
        /// </summary>
        public byte[] Buffer { get; set; }
        /// <summary>
        /// 字节长度
        /// </summary>
        public int Length { get; set; }
        /// <summary>
        /// 是否给Socket返回来自接口的消息，默认返回
        /// </summary>
        public bool IsSend { set; get; } = true;
        /// <summary>
        /// Socket客户端对象
        /// </summary>
        public SocketTcpClient SocketClient { get; }

        /// <summary>
        /// 给客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        public void Send(string message) => SocketClient.Send(message);


        /// <summary>
        /// 给客户端发送消息
        /// </summary>
        /// <param name="buffer"></param>
        public void Send(byte[] buffer) => Send(buffer, 0, buffer.Length);

        /// <summary>
        /// 给客户端发送消息
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        public void Send(byte[] buffer, int offset, int length) => SocketClient.Send(buffer, offset, length);


        /// <summary>
        /// Socket协议类型
        /// </summary>
        public ProtocolType ProtocolType { get; }
        public ReceivedDataEventArgs(SocketTcpClient socketTcpClient, string ip, int port, string machineNo, byte[] buffer, int length, ProtocolType protocolType)
        {
            this.SocketClient = socketTcpClient;
            IP = ip;
            Port = port;
            MachineNo = machineNo;
            Buffer = buffer;
            Length = length;
            ProtocolType = protocolType;
        }
    }
}
